import Vue from 'vue'
import Router from 'vue-router'
import { getToken } from '../utils/auth';

Vue.use(Router)

const router = new Router({
  routes: [
    {
      path: '/',
      name: 'home',
      component: () => import('@/pages/home/index.vue')
    },
	// {
	//   path: '/home',
	//   name: 'home',
	//   component: () => import('@/pages/home/index.vue')
	// },
	{
	  path: '/user',
	  name: 'user',
	  component: () => import('@/pages/user/index.vue')
	},
    {
      path: '/task',
      name: 'task',
      component: () => import('@/pages/task/index.vue')
    },
    {
      path: '/login',
      name: 'login',
      component: () => import('@/pages/login.vue')
    },
    {
      path: '/register',
      name: 'register',
      component: () => import('@/pages/register.vue')
    },
	{
	  path: '/sign-up',
	  name: 'sign-up',
	  component: () => import('@/pages/sign-up.vue')
	}
  ]
})

console.log(router)

router.beforeEach((to, from, next) => {
  const isLogin = getToken()
  if (to.meta.requiresAuth && !isLogin) {
    next('/login');
  } else {
    next();
  }
});

export default router